package com.csaba.connector.dummy;

import java.util.Currency;
import java.util.logging.Logger;

import com.csaba.connector.ServiceException;
import com.csaba.connector.dummy.model.DummyAccount;
import com.csaba.connector.model.Account;
import com.csaba.connector.model.Amount;
import com.csaba.connector.model.Session;
import com.csaba.connector.service.AbstractAccountService;
import com.csaba.util.LoggerHelper;

public class DummyAccountService extends AbstractAccountService
{
	private final static Logger logger = LoggerHelper.getDefaultLogger();

	@Override
	public void execute( final Session session ) throws ServiceException
	{
		if ( session.getCustomer().getId().equals(Codes.ERROR_CUSTOMER) )
			throw new ServiceException("Account Error user caused dummy account error.");

		logger.info("Dummy: account list generated.");
		Codes.waitABit();
		final Account[] result = new Account[2];

		if ( session.getCustomer().getId().equals(Codes.FOREIGN_CUSTOMER) )
		{
			//0
			result[0] = new DummyAccount();
			result[0].setBank(Codes.DUMMY_BANK);
			result[0].setCustomer(session.getCustomer());
			result[0].setNumber("100001001");
			result[0].setName("Local payments");
			result[0].setType("Current LC");
			result[0].setIBAN("HU96 1000 0100 1");
			result[0].setCurrency(Currency.getInstance("HUF"));
			result[0].setAvailableBalance(new Amount(120556, result[0].getCurrency()));
			result[0].setBookedBalance(new Amount(120556, result[0].getCurrency()));
			result[0].setRemoteProperty("status", "active");
			result[0].setRemoteProperty("blocked.amount", new Amount(0, Codes.DUMMY_BANK.getBaseCurrency()));
			result[0].setRemoteProperty("overdraft.limit", new Amount(0, Codes.DUMMY_BANK.getBaseCurrency()));

			//2
			result[1] = new DummyAccount();
			result[1].setBank(Codes.DUMMY_BANK);
			result[1].setCustomer(session.getCustomer());
			result[1].setNumber("100001021");
			result[1].setName("Foreign payments");
			result[1].setType("Current FC");
			result[1].setIBAN("HU42 1000 0102 1");
			result[1].setCurrency(Currency.getInstance("EUR"));
			result[1].setAvailableBalance(new Amount(23000, result[1].getCurrency()));
			result[1].setBookedBalance(new Amount(13000, result[1].getCurrency()));
			result[1].setRemoteProperty("status", "active");
			result[1].setRemoteProperty("blocked.amount", new Amount(0, result[1].getCurrency()));
			result[1].setRemoteProperty("overdraft.limit", new Amount(10000, result[1].getCurrency()));
			result[1].setRemoteProperty("balance.in.base.currency", new Amount(10000, Codes.DUMMY_BANK
					.getBaseCurrency()));
		}
		else if ( session.getCustomer().getId().equals(Codes.LOCAL_CUSTOMER) )
		{
			//0
			result[0] = new DummyAccount();
			result[0].setBank(Codes.DUMMY_BANK);
			result[0].setCustomer(session.getCustomer());
			result[0].setNumber("200001001");
			result[0].setName("My Current");
			result[0].setType("Current LC");
			result[0].setIBAN("HU96 2000 0100 1");
			result[0].setCurrency(Currency.getInstance("HUF"));
			result[0].setAvailableBalance(new Amount(120556, result[0].getCurrency()));
			result[0].setBookedBalance(new Amount(120556, result[0].getCurrency()));
			result[0].setRemoteProperty("status", "active");
			result[0].setRemoteProperty("blocked.amount", new Amount(0, Codes.DUMMY_BANK.getBaseCurrency()));
			result[0].setRemoteProperty("overdraft.limit", new Amount(0, Codes.DUMMY_BANK.getBaseCurrency()));

			//1
			result[1] = new DummyAccount();
			result[1].setBank(Codes.DUMMY_BANK);
			result[1].setCustomer(session.getCustomer());
			result[1].setNumber("200001013");
			result[1].setName("My Deposit");
			result[1].setType("Deposit LC");
			result[1].setIBAN("HU42 2000 0101 3");
			result[1].setCurrency(Currency.getInstance("HUF"));
			result[1].setAvailableBalance(new Amount(0, result[1].getCurrency()));
			result[1].setBookedBalance(new Amount(100000, result[1].getCurrency()));
			result[1].setRemoteProperty("status", "active");
			result[1].setRemoteProperty("maturity.date", "2008-09-01");
			result[1].setRemoteProperty("interest.rate", "5.9900000");
		}
		accounts = result;
	}

}
